home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jedit_typing.tcl < prev    next >
Encoding:
Text File  |  1995-02-08  |  5.6 KB  |  195 lines

  1. # jedit_typing.tcl - special typing procedures for jedit, a tk-based editor
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. # TO DO
  7. #   abbrev fixes:
  8. #     maybe some heuristics for things like plurals
  9. #     maybe a syntax for suffixes (e.g., commit;t -> commitment)
  10. #   file_modes panel
  11. #   documentation for keybindings (automatic documentation?)
  12. #   problem with filename getting set when you cancel Save 
  13. #     for the first time on a new unnamed file
  14. #   improve find panel
  15. #     have find wrap around (if last time didn't match)
  16. #     regex search/replace
  17. #     find all at once (mark) and cycle through with tag nextrange
  18. #   gesture commands
  19. #   autobreaking space a problem if you use two spaces betw sentences
  20. #   word-end punctuation (and heuristics) sd be mode-specific
  21. #
  22. #   PROBLEM WITH CHANGING BINDINGS ON THE FLY!               (urgent)
  23.  
  24. # CHANGES:
  25. #   lots of binding changes (jbind*.tcl consistency)
  26. #     app-specific Emacs and vi bindings
  27. #   house(s) the s won't expand
  28. #   return key checkpoints!
  29. #   improved mode handling (hooks)
  30.  
  31. ######################################################################
  32.  
  33. ######################################################################
  34. # jedit:self_insert_punct - specialised version of j:tkb:self_insert
  35. #   THERE SHOULD BE A GENERALISED MECHANISM FOR THIS!
  36. ######################################################################
  37.  
  38. proc jedit:self_insert_punct { W K A } {
  39.   global j_teb
  40.  
  41.   if {"$A" != ""} {
  42.     jedit:sabbrev_hook $W
  43.     j:tkb:repeatable {
  44.       j:text:insert_string $W $A
  45.     } $W
  46.   }
  47. }
  48.  
  49. ######################################################################
  50. # jedit:tabkey - do whatever tab does (abbrev, indent, whatever)
  51. ######################################################################
  52.  
  53. proc jedit:tabkey { t args } {
  54.   global JEDIT_MODEPREFS
  55.   
  56.   set mode [jedit:get_mode $t]
  57.   
  58.   if {[info procs mode:$mode:pre_tabkey_hook] != {}} {
  59.     mode:$mode:pre_tabkey_hook $t
  60.   }
  61.   #
  62.   if {[info procs mode:$mode:tabkey] != {}} {
  63.     mode:$mode:tabkey $t
  64.   } else {
  65.     if $JEDIT_MODEPREFS($mode,dabbrev) {
  66.       jedit:cmd:dabbrev $t
  67.     } else {
  68.       j:tkb:self_insert $t Tab "\t"
  69.     }
  70.   }
  71.   #
  72.   if {[info procs mode:$mode:post_tabkey_hook] != {}} {
  73.     mode:$mode:post_tabkey_hook $t
  74.   }
  75. }
  76.  
  77. ######################################################################
  78. # jedit:spacebar - do whatever space does (abbrev, line breaking, whatever)
  79. ######################################################################
  80.  
  81. proc jedit:spacebar { t args } {
  82.   set mode [jedit:get_mode $t]
  83.   
  84.   if {[info procs mode:$mode:pre_spacebar_hook] != {}} {
  85.     mode:$mode:pre_spacebar_hook $t
  86.   }
  87.   #
  88.   if {[info procs mode:$mode:spacebar] != {}} {
  89.     mode:$mode:spacebar $t
  90.   } else {
  91.     jedit:sabbrev_hook $t
  92.     j:tkb:self_insert $t space " "
  93.     jedit:autobreak_hook $t
  94.   }
  95.   #
  96.   if {[info procs mode:$mode:post_spacebar_hook] != {}} {
  97.     mode:$mode:post_spacebar_hook $t
  98.   }
  99. }
  100.  
  101. ######################################################################
  102. # jedit:sabbrev_hook t - jedit:cmd:sabbrev if it's on
  103. ######################################################################
  104.  
  105. proc jedit:sabbrev_hook { t } {
  106.   global JEDIT_MODEPREFS
  107.   
  108.   set mode [jedit:get_mode $t]
  109.   
  110.   if $JEDIT_MODEPREFS($mode,sabbrev) {
  111.     jedit:cmd:sabbrev $t
  112.   }
  113. }
  114.  
  115. ######################################################################
  116. # jedit:dabbrev_hook t - jedit:cmd:dabbrev if it's on
  117. ######################################################################
  118. # (not used by plain mode - Tab does dabbrev *INSTEAD OF* inserting
  119. #   tab, not *before* inserting tab)
  120.  
  121. proc jedit:dabbrev_hook { t } {
  122.   global JEDIT_MODEPREFS
  123.   
  124.   set mode [jedit:get_mode $t]
  125.  
  126.   if $JEDIT_MODEPREFS($mode,dabbrev) {
  127.     jedit:cmd:dabbrev $t
  128.   }
  129. }
  130.  
  131. ######################################################################
  132. # jedit:autobreak_hook - insert a cr if line is long enough
  133. ######################################################################
  134.  
  135. proc jedit:autobreak_hook { t } {
  136.   global JEDIT_MODEPREFS
  137.   
  138.   set mode [jedit:get_mode $t]
  139.   
  140.   if $JEDIT_MODEPREFS($mode,autobreak) {
  141.     set length [string length [$t get {insert linestart} insert]]
  142.     if {$length > ($JEDIT_MODEPREFS($mode,textwidth) - 15)} {
  143.       jedit:returnkey $t
  144.     }
  145.   }
  146. }
  147.  
  148. ######################################################################
  149. # jedit:returnkey - do whatever return does (indentation, etc.)
  150. ######################################################################
  151.  
  152. proc jedit:returnkey { t args } {
  153.   set mode [jedit:get_mode $t]
  154.   
  155.   jedit:cmd:save_checkpoint $t
  156.   
  157.   if {[info procs mode:$mode:pre_returnkey_hook] != {}} {
  158.     mode:$mode:pre_returnkey_hook $t
  159.   }
  160.   #
  161.   if {[info procs mode:$mode:returnkey] != {}} {
  162.     mode:$mode:returnkey $t
  163.   } else {
  164.     jedit:sabbrev_hook $t
  165.     j:tkb:self_insert $t Return "\n"
  166.     jedit:autoindent $t
  167.   }
  168.   #
  169.   if {[info procs mode:$mode:post_returnkey_hook] != {}} {
  170.     mode:$mode:post_returnkey_hook $t
  171.   }
  172. }
  173.  
  174. ######################################################################
  175. # jedit:autoindent - insert same indentation as previous line
  176. ######################################################################
  177.  
  178. proc jedit:autoindent { t } {
  179.   global JEDIT_MODEPREFS
  180.   
  181.   set mode [jedit:get_mode $t]
  182.   
  183.   if $JEDIT_MODEPREFS($mode,autoindent) {
  184.     if {[info procs mode:$mode:autoindent] != {}} {
  185.       mode:$mode:autoindent $t
  186.     } else {
  187.       set prevline [$t get {insert -1lines linestart} {insert -1lines lineend}]
  188.       if [regexp "^\[ \t\]\[ \t\]*" $prevline indentation] {
  189.         j:text:insert_string $t $indentation
  190.       }
  191.     }
  192.   }
  193. }
  194.